home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gslib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  16.1 KB  |  550 lines

  1. /* Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gslib.c */
  20. /* Test program for Ghostscript library */
  21. /* Capture stdin/out/err before gs.h redefines them. */
  22. #include <stdio.h>
  23. static FILE *real_stdin, *real_stdout, *real_stderr;
  24. static void
  25. get_real(void)
  26. {    real_stdin = stdin, real_stdout = stdout, real_stderr = stderr;
  27. }
  28. #include "math_.h"
  29. #include "gx.h"
  30. #include "gp.h"
  31. #include "gscdefs.h"
  32. #include "gserrors.h"
  33. #include "gslib.h"
  34. #include "gsmatrix.h"
  35. #include "gsstate.h"
  36. #include "gscspace.h"
  37. #include "gscolor2.h"
  38. #include "gscoord.h"
  39. #include "gsparam.h"
  40. #include "gspaint.h"
  41. #include "gspath.h"
  42. #include "gsstruct.h"
  43. #include "gsutil.h"
  44. #include "gxalloc.h"
  45. #include "gxdevice.h"
  46.  
  47. /* Define whether we are processing captured data. */
  48. /*#define CAPTURE*/
  49.  
  50. /* Test programs */
  51. private void test1(P2(gs_state *, gs_memory_t *));    /* kaleidoscope */
  52. private void test2(P2(gs_state *, gs_memory_t *));    /* pattern fill */
  53. private void test3(P2(gs_state *, gs_memory_t *));    /* RasterOp */
  54. private void test4(P2(gs_state *, gs_memory_t *));    /* set resolution */
  55. #ifdef CAPTURE
  56. #include "k/capture.c"
  57. private void test5(P2(gs_state *, gs_memory_t *));    /* captured data */
  58. #endif
  59. private void (*tests[])(P2(gs_state *, gs_memory_t *)) =
  60.  { test1, test2, test3, test4
  61. #ifdef CAPTURE
  62.   , test5
  63. #endif
  64.  };
  65.  
  66. /* Include the extern for the device list. */
  67. extern_gs_lib_device_list();
  68.  
  69. /* Other imported procedures */
  70.     /* from gsalloc.c */
  71. extern gs_ref_memory_t *ialloc_alloc_state(P2(gs_memory_t *, uint));
  72.  
  73. /* Forward references */
  74. private float odsf(P2(floatp, floatp));
  75.  
  76. int
  77. main(int argc, const char *argv[])
  78. {    char achar;
  79.     gs_ref_memory_t *imem;
  80. #define mem ((gs_memory_t *)imem)
  81.     gs_state *pgs;
  82.     const gx_device **list;
  83.     gx_device *dev;
  84.  
  85.     gp_init();
  86.     get_real();
  87.     gs_stdin = real_stdin;
  88.     gs_stdout = real_stdout;
  89.     gs_stderr = real_stderr;
  90.     gs_lib_init(stdout);
  91.     if ( argc < 2 || (achar = argv[1][0]) < '1' ||
  92.          achar > '0' + countof(tests)
  93.        
  94.        )
  95.       { lprintf1("Usage: gslib 1..%c\n", '0' + countof(tests));
  96.         exit(1);
  97.       }
  98.     gs_debug['@'] = 1;
  99.     gs_debug['?'] = 1;
  100.     /*gs_debug['L'] = 1;*/    /****** PATCH ******/
  101.     imem = ialloc_alloc_state(&gs_memory_default, 20000);
  102.     imem->space = 0;        /****** WRONG ******/
  103.     gs_lib_device_list(&list, NULL);
  104.     gs_copydevice(&dev, list[0], mem);
  105.     /* Print out the device name just to test the gsparam.c API. */
  106.     {    gs_c_param_list list;
  107.         gs_param_string nstr;
  108.         int code;
  109.         gs_c_param_list_write(&list, mem);
  110.         code = gs_getdeviceparams(dev, (gs_param_list *)&list);
  111.         if ( code < 0 )
  112.           { lprintf1("getdeviceparams failed! code = %d\n", code);
  113.             exit(1);
  114.           }
  115.         gs_c_param_list_read(&list);
  116.         code = param_read_string((gs_param_list *)&list, "Name", &nstr);
  117.         if ( code < 0 )
  118.           { lprintf1("reading Name failed! code = %d\n", code);
  119.             exit(1);
  120.           }
  121.         dputs("Device name = ");
  122.         debug_print_string(nstr.data, nstr.size);
  123.         dputs("\n");
  124.         gs_c_param_list_release(&list);
  125.     }
  126.     pgs = gs_state_alloc(mem);
  127.     gs_setdevice_no_erase(pgs, dev);    /* can't erase yet */
  128.     {    gs_point dpi;
  129.         gs_screen_halftone ht;
  130.         gs_dtransform(pgs, 72.0, 72.0, &dpi);
  131.         ht.frequency = min(fabs(dpi.x), fabs(dpi.y)) / 16.001;
  132.         ht.angle = 0;
  133.         ht.spot_function = odsf;
  134.         gs_setscreen(pgs, &ht);
  135.     }
  136.     /* gsave and grestore (among other places) assume that */
  137.     /* there are at least 2 gstates on the graphics stack. */
  138.     /* Ensure that now. */
  139.     gs_gsave(pgs);
  140.     gs_erasepage(pgs);
  141.     (*tests[achar - '1'])(pgs, mem);
  142.     gs_output_page(pgs, 1, 1);
  143.     dputs("Done.  Press <enter> to exit.");
  144.     getchar();
  145.     gs_lib_finit(0, 0);
  146.     return 0;
  147. #undef mem
  148. }
  149. /* Ordered dither spot function */
  150. private float
  151. odsf(floatp x, floatp y)
  152. {    static const byte dither[256] = {
  153. 0x0E,0x8E,0x2E,0xAE,0x06,0x86,0x26,0xA6,0x0C,0x8C,0x2C,0xAC,0x04,0x84,0x24,0xA4,
  154. 0xCE,0x4E,0xEE,0x6E,0xC6,0x46,0xE6,0x66,0xCC,0x4C,0xEC,0x6C,0xC4,0x44,0xE4,0x64,
  155. 0x3E,0xBE,0x1E,0x9E,0x36,0xB6,0x16,0x96,0x3C,0xBC,0x1C,0x9C,0x34,0xB4,0x14,0x94,
  156. 0xFE,0x7E,0xDE,0x5E,0xF6,0x76,0xD6,0x56,0xFC,0x7C,0xDC,0x5C,0xF4,0x74,0xD4,0x54,
  157. 0x01,0x81,0x21,0xA1,0x09,0x89,0x29,0xA9,0x03,0x83,0x23,0xA3,0x0B,0x8B,0x2B,0xAB,
  158. 0xC1,0x41,0xE1,0x61,0xC9,0x49,0xE9,0x69,0xC3,0x43,0xE3,0x63,0xCB,0x4B,0xEB,0x6B,
  159. 0x31,0xB1,0x11,0x91,0x39,0xB9,0x19,0x99,0x33,0xB3,0x13,0x93,0x3B,0xBB,0x1B,0x9B,
  160. 0xF1,0x71,0xD1,0x51,0xF9,0x79,0xD9,0x59,0xF3,0x73,0xD3,0x53,0xFB,0x7B,0xDB,0x5B,
  161. 0x0D,0x8D,0x2D,0xAD,0x05,0x85,0x25,0xA5,0x0F,0x8F,0x2F,0xAF,0x07,0x87,0x27,0xA7,
  162. 0xCD,0x4D,0xED,0x6D,0xC5,0x45,0xE5,0x65,0xCF,0x4F,0xEF,0x6F,0xC7,0x47,0xE7,0x67,
  163. 0x3D,0xBD,0x1D,0x9D,0x35,0xB5,0x15,0x95,0x3F,0xBF,0x1F,0x9F,0x37,0xB7,0x17,0x97,
  164. 0xFD,0x7D,0xDD,0x5D,0xF5,0x75,0xD5,0x55,0xFF,0x7F,0xDF,0x5F,0xF7,0x77,0xD7,0x57,
  165. 0x02,0x82,0x22,0xA2,0x0A,0x8A,0x2A,0xAA,0x00,0x80,0x20,0xA0,0x08,0x88,0x28,0xA8,
  166. 0xC2,0x42,0xE2,0x62,0xCA,0x4A,0xEA,0x6A,0xC0,0x40,0xE0,0x60,0xC8,0x48,0xE8,0x68,
  167. 0x32,0xB2,0x12,0x92,0x3A,0xBA,0x1A,0x9A,0x30,0xB0,0x10,0x90,0x38,0xB8,0x18,0x98,
  168. 0xF2,0x72,0xD2,0x52,0xFA,0x7A,0xDA,0x5A,0xF0,0x70,0xD0,0x50,0xF8,0x78,0xD8,0x58
  169.     };
  170.     int i = (int)((x + 1) * 7.9999);
  171.     int j = (int)((y + 1) * 7.9999);
  172.     return dither[16 * i + j] / 256.0;
  173. }
  174.  
  175. /* Stubs for GC */
  176. const gs_ptr_procs_t ptr_struct_procs = { NULL, NULL, NULL };
  177. const gs_ptr_procs_t ptr_string_procs = { NULL, NULL, NULL };
  178. const gs_ptr_procs_t ptr_const_string_procs = { NULL, NULL, NULL };
  179. void * /* obj_header_t * */
  180. gs_reloc_struct_ptr(const void * /* obj_header_t * */ obj, gc_state_t *gcst)
  181. {    return (void *)obj;
  182. }
  183. void
  184. gs_reloc_string(gs_string *sptr, gc_state_t *gcst)
  185. {
  186. }
  187. void
  188. gs_reloc_const_string(gs_const_string *sptr, gc_state_t *gcst)
  189. {
  190. }
  191.  
  192. /* Other stubs */
  193. void
  194. gs_exit(int exit_status)
  195. {    gs_lib_finit(exit_status, 0);
  196.     exit(exit_status);
  197. }
  198.  
  199.  
  200. /* ---------------- Test program 1 ---------------- */
  201. /* Draw a colored kaleidoscope. */
  202.  
  203. /* Random number generator */
  204. private long rand_state = 1;
  205. private long
  206. rand(void)
  207. {
  208. #define A 16807
  209. #define M 0x7fffffff
  210. #define Q 127773            /* M / A */
  211. #define R 2836                /* M % A */
  212.     rand_state = A * (rand_state % Q) - R * (rand_state / Q);
  213.     /* Note that rand_state cannot be 0 here. */
  214.     if ( rand_state <= 0 ) rand_state += M;
  215. #undef A
  216. #undef M
  217. #undef Q
  218. #undef R
  219.     return rand_state;
  220. }
  221. private void
  222. test1(gs_state *pgs, gs_memory_t *mem)
  223. {    int n;
  224.     gs_scale(pgs, 72.0, 72.0);
  225.     gs_translate(pgs, 4.25, 5.5);
  226.     gs_scale(pgs, 4.0, 4.0);
  227.     gs_newpath(pgs);
  228.     for ( n = 200; --n >= 0; )
  229.     {    int j;
  230. #define rf() (rand() / (1.0 * 0x10000 * 0x8000))
  231.         double r = rf(), g = rf(), b = rf();
  232.         double x0=rf(), y0=rf(), x1=rf(), y1=rf(), x2=rf(), y2=rf();
  233.         gs_setrgbcolor(pgs, r, g, b);
  234.         for ( j = 0; j < 6; j++ )
  235.         {    gs_gsave(pgs);
  236.             gs_rotate(pgs, 60.0 * j);
  237.             gs_moveto(pgs, x0, y0);
  238.             gs_lineto(pgs, x1, y1);
  239.             gs_lineto(pgs, x2, y2);
  240.             gs_fill(pgs);
  241.             gs_grestore(pgs);
  242.         }
  243.     }
  244. #undef mem
  245. }
  246.  
  247. /* ---------------- Test program 2 ---------------- */
  248. /* Fill an area with a pattern. */
  249.  
  250. private void
  251. test2(gs_state *pgs, gs_memory_t *mem)
  252. {    gs_client_color cc;
  253.     gx_tile_bitmap tile;
  254.     /*const*/ byte tpdata[] = {
  255.       /* Define a pattern that looks like this:
  256.         ..xxxx
  257.         .....x
  258.         .....x
  259.         ..xxxx
  260.         .x....
  261.         x.....
  262.        */
  263.       0x3c,0,0,0, 0x04,0,0,0, 0x04,0,0,0, 0x3c,0,0,0,
  264.       0x40,0,0,0, 0x80,0,0,0
  265.     };
  266.  
  267.     gs_newpath(pgs);
  268.     gs_moveto(pgs, 100.0, 300.0);
  269.     gs_lineto(pgs, 500.0, 500.0);
  270.     gs_lineto(pgs, 200.0, 100.0);
  271.     gs_lineto(pgs, 300.0, 500.0);
  272.     gs_lineto(pgs, 500.0, 200.0);
  273.     gs_closepath(pgs);
  274.     gs_setrgbcolor(pgs, 0.0, 0.0, 0.0);
  275.     gs_gsave(pgs);
  276.     gs_fill(pgs);
  277.     gs_grestore(pgs);
  278.     tile.data = tpdata;
  279.     tile.raster = 4;
  280.     tile.size.x = tile.rep_width = 6;
  281.     tile.size.y = tile.rep_height = 6;
  282.     tile.id = gx_no_bitmap_id;
  283.     gs_makebitmappattern(&cc, &tile, true, pgs, NULL);
  284.     /* Note: color space is DeviceRGB */
  285.     cc.paint.values[0] = 0.0;
  286.     cc.paint.values[1] = 1.0;
  287.     cc.paint.values[2] = 1.0;
  288.     gs_setpattern(pgs, &cc);
  289.     gs_eofill(pgs);
  290.     gs_makebitmappattern(&cc, &tile, false, pgs, NULL);
  291.     gs_setcolor(pgs, &cc);
  292.     gs_moveto(pgs, 50.0, 50.0);
  293.     gs_lineto(pgs, 300.0, 50.0);
  294.     gs_lineto(pgs, 50.0, 300.0);
  295.     gs_closepath(pgs);
  296.     gs_setrgbcolor(pgs, 1.0, 0.0, 0.0);
  297.     gs_gsave(pgs);
  298.     gs_fill(pgs);
  299.     gs_grestore(pgs);
  300.     gs_setpattern(pgs, &cc);
  301.     gs_eofill(pgs);
  302. }
  303.  
  304. /* ---------------- Test program 3 ---------------- */
  305. /* Exercise RasterOp a little. */
  306. /* Currently, this only works with monobit devices. */
  307.  
  308. private void
  309. test3(gs_state *pgs, gs_memory_t *mem)
  310. {    gx_device *dev = gs_currentdevice(pgs);
  311.     gx_color_index black =
  312.       (*dev_proc(dev, map_rgb_color))(dev, 0, 0, 0);
  313.     gx_color_index white =
  314.       (*dev_proc(dev, map_rgb_color))(dev, gx_max_color_value,
  315.                       gx_max_color_value,
  316.                       gx_max_color_value);
  317.     gx_color_index black2[2];
  318.     gx_color_index black_white[2];
  319.     gx_color_index white_black[2];
  320.     long pattern[max(align_bitmap_mod / sizeof(long), 1) * 4];
  321. #define pbytes ((byte *)pattern)
  322.     gx_tile_bitmap tile;
  323.  
  324.     black2[0] = black2[1] = black;
  325.     black_white[0] = white_black[1] = black;
  326.     black_white[1] = white_black[0] = white;
  327.     pbytes[0] = 0xf0;
  328.     pbytes[align_bitmap_mod] = 0x90;
  329.     pbytes[align_bitmap_mod*2] = 0x90;
  330.     pbytes[align_bitmap_mod*3] = 0xf0;
  331.     tile.data = pbytes;
  332.     tile.raster = align_bitmap_mod;
  333.     tile.size.x = tile.size.y = 4;
  334.     tile.id = gs_next_ids(1);
  335.     tile.rep_width = tile.rep_height = 4;
  336.     (*dev_proc(dev, copy_rop))
  337.       (dev, NULL, 0, 0, gx_no_bitmap_id, black2,
  338.        &tile, white_black, 100, 100, 150, 150, 0, 0, rop3_T);
  339.     (*dev_proc(dev, copy_rop))
  340.       (dev, NULL, 0, 0, gx_no_bitmap_id, black2,
  341.        NULL, NULL, 120, 120, 110, 110, 0, 0, ~rop3_S & rop3_1);
  342.     (*dev_proc(dev, copy_rop))
  343.       (dev, NULL, 0, 0, gx_no_bitmap_id, black2,
  344.        &tile, white_black, 110, 110, 130, 130, 0, 0, rop3_T ^ rop3_D);
  345. #undef pbytes
  346. }
  347.  
  348. /* ---------------- Test program 4 ---------------- */
  349. /* Set the resolution dynamically. */
  350.  
  351. private void
  352. test4(gs_state *pgs, gs_memory_t *mem)
  353. {    gs_c_param_list list;
  354.     float resv[2];
  355.     gs_param_float_array ares;
  356.     int code;
  357.     gx_device *dev = gs_currentdevice(pgs);
  358.  
  359.     gs_c_param_list_write(&list, mem);
  360.     resv[0] = resv[1] = 100;
  361.     ares.data = resv;
  362.     ares.size = 2;
  363.     ares.persistent = true;
  364.     code = param_write_float_array((gs_param_list *)&list,
  365.                        "HWResolution", &ares);
  366.     if ( code < 0 )
  367.       { lprintf1("Writing HWResolution failed: %d\n", code);
  368.         exit(1);
  369.       }
  370.     gs_c_param_list_read(&list);
  371.     code = gs_putdeviceparams(dev, (gs_param_list *)&list);
  372.     gs_c_param_list_release(&list);
  373.     if ( code < 0 )
  374.       { lprintf1("Setting HWResolution failed: %d\n", code);
  375.         exit(1);
  376.       }
  377.     gs_initmatrix(pgs);
  378.     gs_initclip(pgs);
  379.     if ( code == 1 )
  380.     { code = (*dev_proc(dev, open_device))(dev);
  381.       if ( code < 0 )
  382.         { lprintf1("Reopening device failed: %d\n", code);
  383.           exit(1);
  384.         }
  385.     }
  386.     gs_moveto(pgs, 0.0, 72.0);
  387.     gs_rlineto(pgs, 72.0, 0.0);
  388.     gs_rlineto(pgs, 0.0, 72.0);
  389.     gs_closepath(pgs);
  390.     gs_stroke(pgs);
  391. }
  392.  
  393. #ifdef CAPTURE
  394.  
  395. /* ---------------- Test program 5 ---------------- */
  396. /* Replay captured data for printer output. */
  397.  
  398. private const char outfile[] = "t.pbm";
  399. private const float ypage_wid = 11.0;
  400. private const float xpage_len = 17.0;
  401. private const int rotate_value = 0;
  402. private const float scale_x = 0.45;
  403. private const float scale_y = 0.45;
  404. private const float xmove_origin = 0.0;
  405. private const float ymove_origin = 0.0;
  406.  
  407. private void
  408. test5(gs_state *pgs, gs_memory_t *mem)
  409. {    gs_c_param_list list;
  410.     gs_param_string nstr, OFstr;
  411.     gs_param_float_array PSa;
  412.     gs_param_float_array HWRa;
  413.     gs_param_int_array HWSa;
  414.     int HWSize[2];
  415.     float HWResolution[2], PageSize[2];
  416.     long MaxBitmap;
  417.     int code;
  418.     gx_device *dev = gs_currentdevice(pgs);
  419.     float xlate_x, xlate_y;
  420.     gs_rect cliprect;
  421.  
  422.     gs_c_param_list_write(&list, mem);
  423.     code = gs_getdeviceparams(dev, (gs_param_list *)&list);
  424.     if ( code < 0 )
  425.       { lprintf1("getdeviceparams failed! code = %d\n", code);
  426.         exit(1);
  427.       }
  428.     gs_c_param_list_read(&list);
  429.     code = param_read_string((gs_param_list *)&list, "Name", &nstr);
  430.     if ( code < 0 )
  431.       { lprintf1("reading Name failed! code = %d\n", code);
  432.         exit(1);
  433.       }
  434.     code = param_read_int_array((gs_param_list *)&list, 
  435.                     "HWSize", &HWSa);
  436.     if ( code < 0 )
  437.       { lprintf1("reading HWSize failed! code = %d\n", code);
  438.         exit(1);
  439.       }
  440.     eprintf3("HWSize[%d] = [ %d, %d ]\n", HWSa.size,
  441.          HWSa.data[0], HWSa.data[1]);
  442.     code = param_read_float_array((gs_param_list *)&list, 
  443.                       "HWResolution", &HWRa);
  444.     if ( code < 0 )
  445.       { lprintf1("reading Resolution failed! code = %d\n", code);
  446.         exit(1);
  447.       }
  448.     eprintf3("HWResolution[%d] = [ %f, %f ]\n", HWRa.size,
  449.          HWRa.data[0], HWRa.data[1]);
  450.     code = param_read_float_array((gs_param_list *)&list, 
  451.                       "PageSize", &PSa);
  452.     if ( code < 0 )
  453.       { lprintf1("reading PageSize failed! code = %d\n", code);
  454.         exit(1);
  455.       }
  456.     eprintf3("PageSize[%d] = [ %f, %f ]\n", PSa.size,
  457.          PSa.data[0], PSa.data[1]);
  458.     code = param_read_long((gs_param_list *)&list, 
  459.                    "MaxBitmap", &MaxBitmap);
  460.     if ( code < 0 )
  461.       { lprintf1("reading MaxBitmap failed! code = %d\n", code);
  462.         exit(1);
  463.       }
  464.     eprintf1("MaxBitmap = %ld\n", MaxBitmap );
  465.     /* Switch to param list functions to "write" */
  466.     gs_c_param_list_write(&list, mem);
  467.     /* Always set the PageSize. */
  468.     PageSize[0] = 72.0 * ypage_wid;
  469.     PageSize[1] = 72.0 * xpage_len;
  470.     PSa.data = PageSize;
  471.     code = param_write_float_array((gs_param_list *)&list, 
  472.                        "PageSize", &PSa);
  473.     if( nstr.data[0] != 'v' ) {
  474.       /* Set the OutputFile string file name */
  475.       OFstr.persistent = false;
  476.       OFstr.data = outfile;
  477.       OFstr.size = strlen(outfile);
  478.       code = param_write_string((gs_param_list *)&list, 
  479.                     "OutputFile", &OFstr);
  480.       if ( code < 0 )
  481.         { lprintf1("setting OutputFile name failed, code=%d\n",
  482.                code);
  483.           exit(1);
  484.         }
  485.       if( nstr.data[0] == 'x' ) {
  486.         HWResolution[0] = HWResolution[1] = 72.0;
  487.       }
  488.       else {
  489.         HWResolution[0] = HWResolution[1] = 360.0;
  490.       }
  491.       HWRa.data = HWResolution;
  492.       HWSize[0] = (int) (HWResolution[0] * ypage_wid);
  493.       HWSize[1] = (int) (HWResolution[1] * xpage_len);
  494.       eprintf3("    HWSize = [%d,%d], HWResolution = %f dpi\n", 
  495.            HWSize[0], HWSize[1], HWResolution[0] );
  496.       HWSa.data = HWSize;
  497.       code = param_write_float_array((gs_param_list *)&list, 
  498.                      "HWResolution", &HWRa);
  499.       code = param_write_int_array((gs_param_list *)&list, 
  500.                        "HWSize", &HWSa);
  501.       MaxBitmap = 1000000L;
  502.       code = param_write_long((gs_param_list *)&list, 
  503.                   "MaxBitmap", &MaxBitmap);
  504.     }
  505.     gs_c_param_list_read(&list);
  506.     code = gs_putdeviceparams(dev, (gs_param_list *)&list);
  507.     eprintf1("putdeviceparams: code=%d\n", code);
  508.     gs_c_param_list_release(&list);
  509.  
  510.     gs_erasepage(pgs);
  511.     gs_initgraphics(pgs);
  512.     gs_clippath( pgs );
  513.     gs_pathbbox( pgs, &cliprect );
  514.     eprintf4("    cliprect = [[%g,%g],[%g,%g]]\n",
  515.          cliprect.p.x, cliprect.p.y, cliprect.q.x, cliprect.q.y);
  516.     gs_newpath( pgs );
  517.  
  518.     switch( ((rotate_value+270)/90) & 3 ) {
  519.        default:
  520.        case 0:    /* 0 = 360 degrees in PS == 90 degrees in printer */
  521.           xlate_x = cliprect.p.x; xlate_y = cliprect.p.y;
  522.           break;
  523.        case 1:    /* 90 degrees in PS = 180 degrees printer */
  524.           xlate_x = cliprect.q.x; xlate_y = cliprect.p.y;
  525.           break;
  526.        case 2:    /* 180 degrees in PS == 270 degrees in printer */
  527.           xlate_x = cliprect.q.x; xlate_y = cliprect.q.y;
  528.           break;
  529.        case 3:    /* 270 degrees in PS == 0 degrees in printer */
  530.           xlate_x = cliprect.p.x; xlate_y = cliprect.q.y;
  531.           break;
  532.     }
  533.     eprintf2("translate origin to [ %f, %f ]\n", xlate_x, xlate_y);
  534.         gs_translate( pgs, xlate_x, xlate_y );
  535.  
  536.        /* further move (before rotate) by user requested amount */
  537.     gs_translate( pgs, 72.0*(float)xmove_origin, 72.0*(float)ymove_origin );
  538.  
  539.     gs_rotate( pgs, (float)rotate_value + 270.0 );
  540.     gs_scale( pgs, scale_x*72.0/2032.0, 
  541.             scale_y*72.0/2032.0);
  542.     gs_setlinecap( pgs, gs_cap_butt );
  543.     gs_setlinejoin( pgs, gs_join_bevel );
  544.     gs_setfilladjust(pgs, 0.0, 0.0);
  545.  
  546.     capture_exec(pgs);
  547. }
  548.  
  549. #endif    /* CAPTURE */
  550.